<?php
include("../fpdf/fpdf.php");
include("../db_connect.php");

class PDF extends FPDF
{
//include 
//setting the statements in loaddata()


	//$m_logo = "";
	//$m_logo = '../../images/mlogo.png';
	
	// Page header
	function Header()
	{
		$this->Image('../images/logo.png',140,5,80,20);
		// Arial bold 15
		$this->SetFont('Arial','B',15);
		// Move to the right
		$this->Cell(1);
		//set the text color
		
		// Title cell(x,y,title,border,?,?);
		$this->Cell(340,30,'Calumpit, Bulacan',0,0,'C');
		// Line break
		$this->Ln(10);	
		
		$this->SetFont('Arial','I',15);
		$this->Cell(130,25,'Basci Auto Sales Parts List',0,0,'C');
		$this->Ln(20);	
	}

	// Page footer
	function Footer()
	{
		// Position at 1.5 cm from bottom
		$this->SetY(-15);
		// Arial italic 8
		$this->SetFont('Arial','',8);
		// Page number
		$this->Cell(0,10,'Page '.$this->PageNo().' Part List',0,0,'C');
		
	}
	
	function LoadData(){
		include("../db_connect.php");	
		
		$sql = "SELECT * FROM tblswaping where addoff = '1' AND categories like'%Acccessories%' order by id DESC";
		$result = mysql_query($sql)or die(mysql_error());
		
		while($row=mysql_fetch_row($result)){ 
			$data[] = $row;
		}
		return $data;
		
		
	}


	//Colored table
	// Colored table
	function FancyTable($header, $data){
		
	//Colors, line width and bold font
			//Colors, line width and bold font
			$this->Cell(30);
			$this->SetFillColor(70,70,70);
			$this->SetTextColor(255);
			$this->SetDrawColor(128,0,0);
			$this->SetLineWidth(.3);
			$this->SetFont('Arial','B',8);
			
			//Header
			$w=array(15,90,50,50,40,20,20);
			$type="";
			for($i=0;$i<count($header);$i++)
			$this->Cell($w[$i],4,$header[$i],1,0,'C',true);
			$this->Ln();
			//Color and font restoration
			$this->SetFillColor(225,235,255);
			$this->SetTextColor(0);
			$this->SetFont('Arial','B',8);
			//Data
			$fill=false;
			foreach($data as $row)
			{
				//$header=array('Txn id','Item Code','Qty','Total Pay','Name','Email','Date');
			$this->Cell(30);
				$this->Cell($w[0],5,$row[0],'LR',0,'L',$fill);
				$this->Cell($w[1],5,$row[1],'LR',0,'L',$fill);
				$this->Cell($w[2],5,$row[6],'LR',0,'L',$fill);
				$this->Cell($w[3],5,$row[7],'LR',0,'L',$fill);
				$this->Cell($w[4],5,$row[3],'LR',0,'L',$fill);
				$this->Cell($w[5],5,$row[10],'LR',0,'L',$fill);
				$this->Cell($w[6],5,$row[12],'LR',0,'L',$fill);
				$this->Ln();
				
				$fill=!$fill;
			}
			$this->Cell(30);
			$this->Cell(array_sum($w),0,'','T');
		$this->Ln(10);
		
	}
	
	

}


$pdf=new PDF('L','mm','Legal');


//Column titles
$header=array('Item Code','Name','Brand','Model','Part','Price','Stock qty');
//Data loading
$data=$pdf->LoadData();

$pdf->AddPage();
$pdf->SetFont('Arial','',10);
// Move to the right
//$pdf->SetMargins(0.5, 0.5);
$pdf->Cell(1);
$pdf->SetFont('Arial','B',10);

$pdf->Ln();
$pdf->FancyTable($header,$data);
$pdf->Output();

mysql_close($con);
?>